BIN             = app
CC              = gcc
CXX             = g++

CURR_DIR        = ${shell pwd}
LVGL_DIR        = ${shell pwd}
LVGL_DIR_NAME   = lvgl

CSRCS           += $(shell find -L $(LVGL_DIR)/$(LVGL_DIR_NAME)/src -name "*.c")
# include $(LVGL_DIR)/$(LVGL_DIR_NAME)/lvgl.mk

# c source files
include drivers/Makefile
include porting/Makefile
CSRCS           += $(shell find -L $(CURR_DIR)/application -name "*.c")
COBJS           += $(patsubst %.c, %.o, $(CSRCS))

# cpp source files
CPPSRCS         += $(shell find -L $(CURR_DIR)/application -name "*.cpp")
CPPOBJS         += $(patsubst %.cpp, %.o, $(CPPSRCS))

CFLAGS          += -I$(LVGL_DIR) \
                   -I$(LVGL_DIR)/$(LVGL_DIR_NAME) \
                   -Idrivers \
                   -Iporting \
                   -Iapplication \
                   -Iapplication/App \
                   -Iapplication/App/Utils \
                   -Iapplication/App/Utils/ArduinoJson \
                   -Iapplication/App/Utils/ArduinoJson/src

LFLAGS          += -lmingw32 -lSDL2main -lSDL2 -lm -lstdc++

$(BIN): $(COBJS) $(CPPOBJS)
	@echo '  LD      $@'       && $(CC) $^ $(CFLAGS) $(LFLAGS) -o $@

%.o:%.c
	@echo '  CC      $^'       && $(CC) $(CFLAGS) -c $^ -o $@

%.o:%.cpp
	@echo '  CXX     $^'       && $(CC) $(CFLAGS) -c $^ -o $@

clean:
	@echo '  CLEAN   $(BIN)'   && rm -rf $(BIN).exe
	@rm -rf $(COBJS) $(CPPOBJS)
